A:
You are looking for the operator %:
Usage:
If a and b are integers, then
a%b = a mod b.
Example:
a = 3 % 4 = 1
The "%" operator is one of the modulo operators.
The modulo operator computes the remainder of a division of the first operand by the second operand.
The expression:
a % b
The remainder of the division of a by b. If the remainder is zero, then the remainder is considered to be 0; otherwise, the remainder is positive or negative depending on the value of the remainder.
For example, if a is 1 and b is 5, then:
1 % 5 = 1
which can be simplified as:
1 % 5 = 4
Example:
a = 1 % 4 = 1
b = 5 % 4 = 1
a % b = 1 % 1 = 4
The modulo operators are a useful way to perform division in this case.
The way they work is that the % can be used instead of a division.
The modulo operator returns the remainder of a division of the first operand by the second operand.
They are defined as:
a mod b = a - (a/b) * b
The modulo operator provides a convenient way to perform division without calculating the quotient and remainder.
The remainder of the division of a by b is returned in the variable, a mod b.
Example:
a = 5
b = 4
a mod b = a - (a/b) * b = a - (5/4) * 4 = a - (5/4) * 4 = a - 5/4 * 4 = a - 1
Note: a mod b is not the same as b mod a. a mod b = (a/b) mod a.
a mod b is a function that returns the remainder of the division of a by b.
b mod a is the inverse of a mod b. a mod b is just the remainder of the division of a by b.
A:
You can do this in one line with math.floor():
var result = 100 - Math.floor(100 / 4.1) * 4.1
Note that ac619d1d87
Related links:
Comentários